package com.tang.factory;

import com.tang.service.Shape;
import com.tang.service.impl.Circle;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 形状工厂
 *
 * @author fulin.tang
 * @version V3.0
 * @since 2021/9/15 17:02
 */
@Slf4j
public class ShapeFactory {
    
    private static final Map<String, Shape> shapeMap = new ConcurrentHashMap<>();
    
    public static Shape getCircle(String color) {
        Shape shape = shapeMap.get(color);
        if (shape == null) {
            shape = new Circle(color);
            shapeMap.put(color, shape);
            log.info("Create circle:{}", shape);
        }
        return shape;
    }
    
}
